package com.seaengine.util
{
	import flash.display.Sprite;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	/**
	 * 此类作用为了设置字体样式提供方便(需要发光效果可以使用此类)
	 * @author 曹鹏
	 */	
	public class GlowFont extends Sprite
	{
	
		//--------------------------------------------------------------------------
		//
		//  variable
		//
		//--------------------------------------------------------------------------
		private var textField:TextField;
		
		private var textFormat:TextFormat;
		
		/**发光效果*/
		private var glowFilter:GlowFilter
		
		/**
		 * 发光字体类
		 * @param color	   颜色
		 * @param size	   大小
		 */		
		public function GlowFont(color$:uint=0,size$:uint=0)
		{
			super();
			init();
			
			if(color$ != 0)
			{
				color = color$;
			}
			if(size$ != 0)
			{
				size = size$;
			}
		}
	
		//--------------------------------------------------------------------------
		//
		//  property
		//
		//--------------------------------------------------------------------------
		private var _font:String = "宋体";

		/**
		 * 字体样式
		 */
		public function set font(value:String):void
		{
			_font = value;
			textFormat.font = value;
		}

		private var _size:uint = 12;

		/**
		 * 字体大小
		 */
		public function set size(value:uint):void
		{
			_size = value;
			textFormat.size = value;
		}

		private var _color:uint = 0xFFFFFF;

		/**
		 * 字体颜色
		 */		
		public function set color(value:uint):void
		{
			_color = value;
			textField.textColor = _color;
		}
		
		/**对齐方式*/
		private var _align:String = TextFormatAlign.LEFT;
		
		public function set align(value:String):void
		{
			_align = value;
			textFormat.align = _align;
		}
		
		private var _text:String = "";

		/**
		 * 内容
		 */
		public function set text(value:String):void
		{
			_text = value;
			textField.htmlText = value;
			textField.width = textField.textWidth + 20;
			textField.setTextFormat(textFormat);
			this.width=textField.width+40;
		}
		
		//--------------------------------------------------------------------------
		//
		//  public
		//
		//--------------------------------------------------------------------------
		/**
		 * 字体发光效果参数
		 * @param color 光晕颜色
		 * @param alpha 颜色的 Alpha 透明度值
		 * @param blurX 水平模糊量
		 * @param blurY 垂直模糊量
		 * @param strength 印记或跨页的强度
		 * @param quality  应用滤镜的次数
		 * @param inner    指定发光是否为内侧发光
		 * @param knockout 指定对象是否具有挖空效果
		 */		
		public function glowParameter(color:uint=0x000000,alpha:Number=1,blurX:Number=4.0,blurY:Number=4.0,
									  strength:Number=2,quality:uint=1,inner:Boolean=false,knockout:Boolean=false):void
		{
			glowFilter = new GlowFilter(color,alpha,blurX,blurY,strength,quality,inner,knockout);
			textField.filters = [glowFilter];
		}
		//--------------------------------------------------------------------------
		//
		//  private
		//
		//--------------------------------------------------------------------------
		private function init():void
		{
			textField = new TextField();
			textFormat = new TextFormat();
			glowParameter();
			textFormat.size = _size;
			textFormat.font = _font;
			textField.textColor = _color;
			textField.mouseEnabled = false;
			this.mouseEnabled = false;
			this.mouseChildren = false;
			this.addChild(textField);
		}
	}
}